﻿using UnityEditor;
using UnityEngine;
using System.Collections;

[CustomEditor(typeof(PUEXBoxEmitter))]
public class PUEXBoxEmitterEditor : Editor {

	public void OnSceneGUI ()
	{
		var affector = target as PUEXBoxEmitter;
		if (!affector.enabled)
			return;
		
		Matrix4x4 defaultMatrix = Handles.matrix;
		Handles.matrix = affector.transform.localToWorldMatrix;
		
		Quaternion quat = Quaternion.Euler (-affector.directionAngle, 0, 0);
		Vector3 center = Vector3.zero;
//		if (Tools.current == Tool.Rotate) {
//			quat = Handles.RotationHandle (quat, center);
//			
//			if (GUI.changed) {
//				Undo.RecordObject(affector, "PUEXBoxEmitter Modify");
//				affector.directionAngle = -quat.eulerAngles.x;
//				EditorUtility.SetDirty(affector);
//			}
//		}
		
		Vector3 dir = center + quat * Vector3.forward * HandleUtility.GetHandleSize(center) * 2f;
		Handles.DrawLine (center, dir);
		Handles.ConeCap(0, dir, quat, HandleUtility.GetHandleSize(center) * 0.2f);

		Handles.matrix = defaultMatrix;
	}

}
